package com.evan.uyclub.OtherImageTool;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

import com.evan.uyclub.Other.Utlis;
import com.evan.uyclub.R;
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
import com.google.android.material.textfield.TextInputEditText;
import com.sdsmdg.tastytoast.TastyToast;
import com.tapadoo.alerter.Alerter;


public class EkiCode extends AppCompatActivity {

    private ImageView dowimg, setimg;
    private ExtendedFloatingActionButton yes;
    private TextInputEditText edit;
    private Bitmap setsimg;

    @Override
    protected void onCreate(Bundle s) {
        super.onCreate(s);
        setContentView(R.layout.activity_qr);

        //获取
        dowimg = findViewById(R.id.down);
        setimg = findViewById(R.id.compress_img);
        yes = findViewById(R.id.fab);
        edit = findViewById(R.id.textInputEditText);

        //返回
        ImageView back = (ImageView) findViewById(R.id.back);
        back.setOnClickListener(view -> {
            this.finish();
        });

        initView();
    }

    private void initView() {
        yes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String Condata = edit.getText().toString().trim();
                if (Condata.equals("")) {
                    TastyToast.makeText(EkiCode.this, "输入数据哦~", TastyToast.LENGTH_SHORT, TastyToast.ERROR);
                } else {
                    setsimg = Utlis.qrcode(Condata);
                    setimg.setImageBitmap(setsimg);
                }

                dowimg.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Utlis.fileSaveToPublic(EkiCode.this, "QR_img", setsimg);
                        TastyToast.makeText(EkiCode.this, "模糊成功喽~", TastyToast.LENGTH_SHORT, TastyToast.SUCCESS).show();
                        Alerter.create(EkiCode.this)
                                .setTitle(getString(R.string.keep_succes))
                                .setText(getString(R.string.keep_foto))
                                .setDuration(1200)
                                .setBackgroundColorRes(R.color.green)
                                .show();
                    }
                });
            }
        });
    }
}
